import java.util.Scanner;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CollectionTest {
    private Stack<String> stack;

    private String initalStr = null;

// 最终字符串

        private String finalStr = null;
// 中间字符串

    StringBuffer sb = new StringBuffer();


    private static int cursor = 0;

private String gro = null;
public CollectionTest() {
stack = new Stack<String>();

}

private String reverseWord(String str) {


    Pattern p = Pattern.compile("[\\W&&[^\\u4e00-\\u9fa5]]+");
Matcher m = p.matcher(str);
m.find();

gro = m.group();



for (cursor = 0; cursor < str.length(); cursor++) {

 if (cursor == m.start()) {

int n = stack.size();

for (int i = 1; i <= n; i++) {

sb.append(stack.pop());

}

continue;
}

else if (cursor > m.start() && cursor < m.end()) {

continue;

}

else if (cursor == m.end()) {

sb.append(gro);
stack.push(String.valueOf(str.charAt(cursor)));
m.find();

gro = m.group();

continue;
}

else {

stack.push(String.valueOf(str.charAt(cursor)));

}

}

sb.append(m.group());



return sb.toString();

}

@SuppressWarnings("resource")

public static void main(String[] args) {

CollectionTest coll = new CollectionTest();

 Scanner sc = new Scanner(System.in);

coll.initalStr = sc.nextLine();

System.out.println("初始语句为：" + coll.initalStr);



coll.finalStr = coll.reverseWord(coll.initalStr);

System.out.println("反转后语句为：" + coll.finalStr);
}

}
